<template>
    <div>
        <ul class="mui-table-view">
            <li   v-for="item in newsList"  class="mui-table-view-cell mui-media">
                <router-link :to="`newsInfo/${item.id}`">
                    <img class="mui-media-object mui-pull-left" :src="item.img_url">
                    <div class="mui-media-body">
                        {{ item.title }}
                        <p class="mui-ellipsis">
                            <span>发表时间：{{ item.add_time | filterTime }}</span><span>点击：{{ item.click }}次</span>
                        </p>
                    </div>
                </router-link>
            </li>
        </ul>
    </div>
</template>

<script>
    // 引入 提示框
    import { Toast } from 'mint-ui'
    export default {
        data: function () {
            return {
                newsList: [],
            }
        },
        created() {
            this.getNewList()

        },
        methods: {
            // 获取新闻列表
            getNewList() {
                this.$http.get('api/getnewslist')
                    .then(function (data) {
                        // 数据获取失败
                        if (data.body.status !== 0) return toastFn('数据获取失败')
                        // success
                        this.newsList = data.body.message
                    }, function () {
                        toastFn('Server error 500')
                    })
            }
        },
    }

    // 服务器错误 函数
    function toastFn (msg) {
        Toast({
            message: msg,
            position: 'middle',
            duration: 5000
        })
    }
</script>

<style lang="less" scoped>
    .mui-table-view{
        .mui-media-body{
            font-size: 14px;
            .mui-ellipsis{
                font-size: 12px;
                color: #226aff;
                display: flex;
                justify-content: space-between;
            }
        }
    }
</style>